﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Address_Book
{
    public partial class frmImport : Form
    {
        public frmImport()
        {
            InitializeComponent();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (radioButton1.Checked == true)
            {
                OpenFileDialog of = new OpenFileDialog();
                of.Filter = "QQ_CSV文件|*.CSV";
                if (of.ShowDialog() == DialogResult.Cancel)
                {
                    return;
                }
                else
                {
                    string fileName = of.FileName;
                    FileStream fs = new FileStream(fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                    StreamReader sr = new StreamReader(fs, System.Text.Encoding.Default);
                    Address_Book.BLL.Import import = new Address_Book.BLL.Import();
                    MessageBox.Show( import.ImpotrQQCSV(sr)+"条记录成功导入系统。","提示");
                }
            }
            else if (radioButton2.Checked == true)
            {
                OpenFileDialog of = new OpenFileDialog();
                of.Filter = "Fetion_CSV文件|*.CSV";
                if (of.ShowDialog() == DialogResult.Cancel)
                {
                    return;
                }
                else
                {
                    string fileName = of.FileName;
                    FileStream fs = new FileStream(fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                    StreamReader sr = new StreamReader(fs, System.Text.Encoding.Default);
                    Address_Book.BLL.Import import = new Address_Book.BLL.Import();
                    MessageBox.Show(import.ImpotrFetionCSV(sr) + "条记录成功导入系统。", "提示");
                    this.Close();
                }
            }
            else
            {
                OpenFileDialog of = new OpenFileDialog();
                of.Filter = "Addressbook_CSV文件|*.CSV";
                if (of.ShowDialog() == DialogResult.Cancel)
                {
                    return;
                }
                else
                {
                    string fileName = of.FileName;
                    FileStream fs = new FileStream(fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                    StreamReader sr = new StreamReader(fs, System.Text.Encoding.Default);
                    Address_Book.BLL.Import import = new Address_Book.BLL.Import();
                    MessageBox.Show(import.ImpotrAddressBookCSV(sr) + "条记录成功导入系统。", "提示");
                    this.Close();
                }
            }
        }
    }
}